﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bzure.Common.Core;

namespace Bzure.Common.Data
{
    public interface IPostEntity : IEntity
    {
        EntityPostRequest ToUpdateRequest();
        EntityPostRequest ToDeleteRequest();
    }
    public static class PostEntityExtensions
    {
        public static void UpdateEntity(this IPostEntity entity, string ProviderName)
        {
            Actor.Public.BuildEntityProcessor(ProviderName).UpdateEntity(entity.ToUpdateRequest());
        }
        public static void DeleteEntity(this IPostEntity entity, string ProviderName)
        {
            Actor.Public.BuildEntityProcessor(ProviderName).UpdateEntity(entity.ToDeleteRequest());
        }
        public static void UpdateEntity<T>(this HistoryEntity<T> entity, string ProviderName) where T : class, IPostEntity
        {
            Actor.Public.BuildEntityProcessor(ProviderName).UpdateEntity(entity.Entity.ToUpdateRequest());
        }
        public static void DeleteEntity<T>(this HistoryEntity<T> entity, string ProviderName) where T : class , IPostEntity
        {
            Actor.Public.BuildEntityProcessor(ProviderName).UpdateEntity(entity.Entity.ToDeleteRequest());
        }
        public static EntityPostRequest ToUpdateRequest<T>(this HistoryEntity<T> entity) where T : class, IPostEntity
        {
            return entity.Entity.ToUpdateRequest();
        }
        public static EntityPostRequest ToDeleteRequest<T>(this HistoryEntity<T> entity) where T : class , IPostEntity
        {
            return entity.Entity.ToDeleteRequest();
        }
    }
}
